﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Client.App.Models;
using Client.App.Services;
using Client.App.ViewModels.Implementations;
using Client.App.ViewModels.Interfaces;
using Multiprocessing.Algorithms.Algebra;
using Multiprocessing.Algorithms.Matrices;
using Multiprocessing.Core.Units;

namespace Client.App
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {

            base.OnStartup(e);
            /*
            // initialize algorithms
            IAlgorithmsViewModel algorithms = new AlgorithmsViewModel();
            AlgorithmFamily matricesFamily = new AlgorithmFamily {Name = "Алгоритмы на матрицах"};
            matricesFamily.Algorithms.Add(new MultiplyMatricesAlgorithm("Классическое умножение матриц"));
            AlgorithmFamily primeNumberProblem = new AlgorithmFamily() {Name = "Простые числа"}; 
            primeNumberProblem.Algorithms.Add(new PrimeNumberProblemAlgorithm("Классическая проверка на простоту"));
                 
            algorithms.AlgorithmFamilies.Add(matricesFamily);
            algorithms.AlgorithmFamilies.Add(primeNumberProblem);
            */
            IEnumerable<AlgorithmFamily> families = AlgorithmsLoader.Instance.GetAlgorithmFamilies("Algorithms.xml");
            IAlgorithmsViewModel algorithmsViewModel = new AlgorithmsViewModel(families);


            IMainViewModel mainViewModel = new MainViewModel(this.Dispatcher, ConfigurationService.Instance,
                                                             new EfficiencyAccelerationViewModel(this.Dispatcher, ConfigurationService.Instance),
                                                             new DataTimeTestViewModel(this.Dispatcher), algorithmsViewModel);
            MainWindow mainWindow = new MainWindow {DataContext = mainViewModel};
            this.MainWindow = mainWindow;
            mainWindow.Closing += (s, args) =>
                                      {
                                          var result = Xceed.Wpf.Toolkit.MessageBox.Show(this.MainWindow, "Вы уверены?",
                                                                                         "Выход", MessageBoxButton.YesNo,
                                                                                         MessageBoxImage.Question,
                                                                                         MessageBoxResult.No);
                                          if (result == MessageBoxResult.Yes)
                                          {
                                              mainViewModel.Dispose();
                                          }
                                          else
                                          {
                                              args.Cancel = true;
                                          }
                                      };
            mainViewModel.RequestClose += (s, args) => this.MainWindow.Close();
            mainWindow.Show();

        }
    }
}
